/*   1:    */ package org.jetbrains.debugger.sourcemap;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Url;
import com.intellij.util.UrlImpl;
import com.intellij.util.Urls;
import com.intellij.util.containers.ObjectIntHashMap;
import com.intellij.util.text.CaseInsensitiveStringHashingStrategy;
import gnu.trove.TObjectIntHashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.io.LocalFileFinder;

import java.util.Iterator;
import java.util.List;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */ 
/*  19:    */ public class SourceResolver
/*  20:    */ {
/*  21:    */   private final List<String> a;
/*  22:    */   final Url[] canonicalizedSources;
/*  23:    */   private final ObjectIntHashMap<Url> b;
/*  24:    */   private TObjectIntHashMap<String> c;
/*  25:    */   private String[] d;
/*  26:    */   
/*  27:    */   public SourceResolver(@NotNull List<String> paramList, boolean paramBoolean, @Nullable Url paramUrl)
/*  28:    */   {
/*  29: 32 */     this.a = paramList;
/*  30: 33 */     this.canonicalizedSources = new Url[paramList.size()];
/*  31: 34 */     this.b = (SystemInfo.isFileSystemCaseSensitive ? new ObjectIntHashMap(this.canonicalizedSources.length) : new ObjectIntHashMap(this.canonicalizedSources.length, Urls.getCaseInsensitiveUrlHashingStrategy()));
/*  32: 37 */     for (int i = 0; i < paramList.size(); i++)
/*  33:    */     {
/*  34: 38 */       Url localUrl = a((String)paramList.get(i), paramUrl, paramBoolean, i);
/*  35: 39 */       this.canonicalizedSources[i] = localUrl;
/*  36: 40 */       this.b.put(localUrl, i);
/*  37:    */     }
/*  38:    */   }
/*  39:    */   
/*  40:    */   public static boolean isAbsolute(@NotNull String paramString)
/*  41:    */   {
/*  42: 45 */     if (paramString == null) {
/*  43: 45 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/sourcemap/SourceResolver", "isAbsolute" }));
/*  44:    */     }
/*  45: 45 */     return (!paramString.isEmpty()) && ((paramString.charAt(0) == '/') || ((SystemInfo.isWindows) && (paramString.length() > 2) && (paramString.charAt(1) == ':')));
/*  46:    */   }
/*  47:    */   
/*  48:    */   private Url a(@NotNull String paramString, @Nullable Url paramUrl, boolean paramBoolean, int paramInt)
/*  49:    */   {
/*  50: 50 */     if (paramString == null) {
/*  51: 50 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/sourcemap/SourceResolver", "canonicalizeUrl" }));
/*  52:    */     }
/*  53: 50 */     if ((paramBoolean) && (paramString.startsWith("file://"))) {
/*  54: 51 */       return Urls.newLocalFileUrl(FileUtil.toCanonicalPath(VfsUtilCore.toIdeaUrl(paramString, true).substring("file://".length()), '/'));
/*  55:    */     }
/*  56: 53 */     if ((paramUrl == null) || (paramString.contains("://")) || (paramString.startsWith("data:")) || (paramString.startsWith("blob:")) || (paramString.startsWith("javascript:"))) {
/*  57: 54 */       return Urls.parseEncoded(paramString);
/*  58:    */     }
/*  59: 57 */     String str1 = paramString;
/*  60:    */     Object localObject;
/*  61: 58 */     if (paramString.charAt(0) != '/')
/*  62:    */     {
/*  63: 59 */       localObject = paramUrl.getPath();
/*  64: 60 */       int i = ((String)localObject).lastIndexOf('/');
/*  65: 61 */       StringBuilder localStringBuilder = new StringBuilder();
/*  66: 62 */       if (i == -1) {
/*  67: 63 */         localStringBuilder.append((String)localObject).append('/');
/*  68:    */       } else {
/*  69: 66 */         localStringBuilder.append((CharSequence)localObject, 0, i + 1);
/*  70:    */       }
/*  71: 68 */       str1 = paramString;
/*  72:    */     }
/*  73: 70 */     str1 = FileUtil.toCanonicalPath(str1, '/');
/*  74: 72 */     if ((paramUrl.getScheme() == null) && (paramUrl.isInLocalFileSystem())) {
/*  75: 73 */       return Urls.newLocalFileUrl(str1);
/*  76:    */     }
/*  77: 77 */     if (isAbsolute(str1))
/*  78:    */     {
/*  79: 78 */       localObject = LocalFileFinder.findFile(str1);
/*  80: 79 */       if (localObject != null)
/*  81:    */       {
/*  82: 80 */         if (this.c == null)
/*  83:    */         {
/*  84: 82 */           this.c = (SystemInfo.isFileSystemCaseSensitive ? new ObjectIntHashMap(this.a.size()) : new ObjectIntHashMap(this.a.size(), CaseInsensitiveStringHashingStrategy.INSTANCE));
/*  85:    */           
/*  86:    */ 
/*  87: 85 */           this.d = new String[this.a.size()];
/*  88:    */         }
/*  89: 87 */         this.c.put(str1, paramInt);
/*  90: 88 */         this.d[paramInt] = str1;
/*  91: 89 */         String str2 = ((VirtualFile)localObject).getCanonicalPath();
/*  92: 90 */         if ((str2 != null) && (!str2.equals(str1))) {
/*  93: 91 */           this.c.put(str2, paramInt);
/*  94:    */         }
/*  95:    */       }
/*  96:    */     }
/*  97: 95 */     return new UrlImpl(paramUrl.getScheme(), paramUrl.getAuthority(), str1, null);
/*  98:    */   }
/*  99:    */   
/* 100:    */   @Nullable
/* 101:    */   public Url getSource(@NotNull MappingEntry paramMappingEntry)
/* 102:    */   {
/* 103:100 */     if (paramMappingEntry == null) {
/* 104:100 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/sourcemap/SourceResolver", "getSource" }));
/* 105:    */     }
/* 106:100 */     int i = paramMappingEntry.getSource();
/* 107:101 */     return i < 0 ? null : this.canonicalizedSources[i];
/* 108:    */   }
/* 109:    */   
/* 110:    */   @Nullable
/* 111:    */   public String getRawSource(@NotNull MappingEntry paramMappingEntry)
/* 112:    */   {
/* 113:106 */     if (paramMappingEntry == null) {
/* 114:106 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/sourcemap/SourceResolver", "getRawSource" }));
/* 115:    */     }
/* 116:106 */     int i = paramMappingEntry.getSource();
/* 117:107 */     return i < 0 ? null : (String)this.a.get(i);
/* 118:    */   }
/* 119:    */   
/* 120:    */   @Nullable
/* 121:    */   public String getLocalFilePath(@NotNull MappingEntry paramMappingEntry)
/* 122:    */   {
/* 123:112 */     if (paramMappingEntry == null) {
/* 124:112 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/sourcemap/SourceResolver", "getLocalFilePath" }));
/* 125:    */     }
/* 126:112 */     int i = paramMappingEntry.getSource();
/* 127:113 */     return (i < 0) || (this.d == null) ? null : this.d[i];
/* 128:    */   }
/* 129:    */   
/* 130:    */   @Nullable
/* 131:    */   public MappingList findMappings(@NotNull SourceMap paramSourceMap, @NotNull Resolver paramResolver)
/* 132:    */   {
/* 133:122 */     if (paramSourceMap == null) {
/* 134:122 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/sourcemap/SourceResolver", "findMappings" }));
/* 135:    */     }
/* 136:122 */     if (paramResolver == null) {
/* 137:122 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/debugger/sourcemap/SourceResolver", "findMappings" }));
/* 138:    */     }
/* 139:122 */     int i = paramResolver.resolve(this.b);
/* 140:123 */     return i < 0 ? null : paramSourceMap.sourceIndexToMappings[i];
/* 141:    */   }
/* 142:    */   
/* 143:    */   @Nullable
/* 144:    */   public MappingList findMappings(@NotNull List<Url> paramList, @NotNull SourceMap paramSourceMap, @Nullable VirtualFile paramVirtualFile)
/* 145:    */   {
/* 146:128 */     if (paramList == null) {
/* 147:128 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/sourcemap/SourceResolver", "findMappings" }));
/* 148:    */     }
/* 149:128 */     if (paramSourceMap == null) {
/* 150:128 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/debugger/sourcemap/SourceResolver", "findMappings" }));
/* 151:    */     }
/* 152:128 */     for (Object localObject = paramList.iterator(); ((Iterator)localObject).hasNext();)
/* 153:    */     {
/* 154:128 */       Url localUrl = (Url)((Iterator)localObject).next();
/* 155:129 */       int i = this.b.get(localUrl.trimParameters());
/* 156:130 */       if (i != -1) {
/* 157:131 */         return paramSourceMap.sourceIndexToMappings[i];
/* 158:    */       }
/* 159:    */     }
/* 160:135 */     if (paramVirtualFile != null)
/* 161:    */     {
/* 162:136 */       localObject = a(paramSourceMap, paramVirtualFile);
/* 163:137 */       if (localObject != null) {
/* 164:138 */         return localObject;
/* 165:    */       }
/* 166:    */     }
/* 167:142 */     return null;
/* 168:    */   }
/* 169:    */   
/* 170:    */   @Nullable
/* 171:    */   private MappingList a(@NotNull SourceMap paramSourceMap, @NotNull VirtualFile paramVirtualFile)
/* 172:    */   {
/* 173:147 */     if (paramSourceMap == null) {
/* 174:147 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/sourcemap/SourceResolver", "findByFile" }));
/* 175:    */     }
/* 176:147 */     if (paramVirtualFile == null) {
/* 177:147 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/debugger/sourcemap/SourceResolver", "findByFile" }));
/* 178:    */     }
/* 179:147 */     MappingList localMappingList = null;
/* 180:148 */     if ((this.c != null) && (paramVirtualFile.isInLocalFileSystem()))
/* 181:    */     {
/* 182:149 */       localMappingList = paramSourceMap.sourceIndexToMappings[this.c.get(paramVirtualFile.getPath())];
/* 183:150 */       if (localMappingList == null)
/* 184:    */       {
/* 185:151 */         String str = paramVirtualFile.getCanonicalPath();
/* 186:152 */         if (str != null) {
/* 187:153 */           localMappingList = paramSourceMap.sourceIndexToMappings[this.c.get(str)];
/* 188:    */         }
/* 189:    */       }
/* 190:    */     }
/* 191:158 */     if (localMappingList == null)
/* 192:    */     {
/* 193:159 */       int i = this.b.get(Urls.newFromVirtualFile(paramVirtualFile).trimParameters());
/* 194:160 */       if (i != -1) {
/* 195:161 */         return paramSourceMap.sourceIndexToMappings[i];
/* 196:    */       }
/* 197:164 */       for (int j = 0; j < this.canonicalizedSources.length; j++)
/* 198:    */       {
/* 199:165 */         Url localUrl = this.canonicalizedSources[j];
/* 200:166 */         if (Urls.equalsIgnoreParameters(localUrl, paramVirtualFile)) {
/* 201:167 */           return paramSourceMap.sourceIndexToMappings[j];
/* 202:    */         }
/* 203:170 */         VirtualFile localVirtualFile = paramVirtualFile.getCanonicalFile();
/* 204:171 */         if ((localVirtualFile != null) && (!localVirtualFile.equals(paramVirtualFile)) && (Urls.equalsIgnoreParameters(localUrl, localVirtualFile))) {
/* 205:172 */           return paramSourceMap.sourceIndexToMappings[j];
/* 206:    */         }
/* 207:    */       }
/* 208:    */     }
/* 209:176 */     return localMappingList;
/* 210:    */   }
/* 211:    */   
/* 212:    */   public static abstract interface Resolver
/* 213:    */   {
/* 214:    */     public abstract int resolve(@NotNull ObjectIntHashMap<Url> paramObjectIntHashMap);
/* 215:    */   }
/* 216:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.debugger.sourcemap.SourceResolver

 * JD-Core Version:    0.7.0.1

 */